package com.weiyi.controller.biz;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.weiyi.common.annotation.Log;
import com.weiyi.common.enums.BusinessType;
import com.weiyi.biz.domain.HelmetLog;
import com.weiyi.biz.service.IHelmetLogService;
import com.weiyi.common.core.controller.BaseController;
import com.weiyi.common.core.domain.AjaxResult;
import com.weiyi.common.utils.poi.ExcelUtil;
import com.weiyi.common.core.page.TableDataInfo;

/**
 * 安全帽轨迹Controller
 *
 * @author gq
 * @date 2020-09-18
 */
@Controller
@RequestMapping("/biz/helmet")
public class HelmetLogController extends BaseController
{
    private String prefix = "biz/helmet";

    @Autowired
    private IHelmetLogService helmetLogService;

    @RequiresPermissions("biz:helmet:view")
    @GetMapping()
    public String helmet()
    {
        return prefix + "/helmet";
    }

    /**
     * 查询安全帽轨迹列表
     */
    @RequiresPermissions("biz:helmet:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HelmetLog helmetLog)
    {
        startPage();
        List<HelmetLog> list = helmetLogService.selectHelmetLogList(helmetLog);
        return getDataTable(list);
    }

    /**
     * 导出安全帽轨迹列表
     */
    @RequiresPermissions("biz:helmet:export")
    @Log(title = "安全帽轨迹", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HelmetLog helmetLog)
    {
        List<HelmetLog> list = helmetLogService.selectHelmetLogList(helmetLog);
        ExcelUtil<HelmetLog> util = new ExcelUtil<HelmetLog>(HelmetLog.class);
        return util.exportExcel(list, "helmet");
    }

    /**
     * 新增安全帽轨迹
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存安全帽轨迹
     */
    @RequiresPermissions("biz:helmet:add")
    @Log(title = "安全帽轨迹", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HelmetLog helmetLog)
    {
        return toAjax(helmetLogService.insertHelmetLog(helmetLog));
    }

    /**
     * 修改安全帽轨迹
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HelmetLog helmetLog = helmetLogService.selectHelmetLogById(id);
        mmap.put("helmetLog", helmetLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存安全帽轨迹
     */
    @RequiresPermissions("biz:helmet:edit")
    @Log(title = "安全帽轨迹", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HelmetLog helmetLog)
    {
        return toAjax(helmetLogService.updateHelmetLog(helmetLog));
    }

    /**
     * 删除安全帽轨迹
     */
    @RequiresPermissions("biz:helmet:remove")
    @Log(title = "安全帽轨迹", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(helmetLogService.deleteHelmetLogByIds(ids));
    }
}
